package com.ideacome.test.common.mock.interceptor;

import com.ideacome.common.contants.SymbolConstants;
import org.springframework.cache.interceptor.KeyGenerator;

import java.lang.reflect.Method;

/**
 * 默认mock的key生成器
 *
 * @author 罗成
 */
public class MockKeyGenerator implements KeyGenerator {

    private String keyPrefix;

    public void setKeyPrefix(String keyPrefix) {
        this.keyPrefix = keyPrefix;
    }

    public String getKeyPrefix() {
        return keyPrefix;
    }

    @Override
    public Object generate(Object target, Method method, Object... params) {
        return generateKey(target, method);
    }

    public Object generateKey(Object target, Method method) {
        return getKeyPrefix() + target.getClass().getName() + SymbolConstants.DOT + method.getName();
    }

}
